<?php

namespace maotool\core\text\password\rule;

use maotool\core\text\password\PasswdStrengthRule;
use maotool\core\text\password\result\PasswdStrengthError;
use maotool\core\text\password\result\PasswdStrengthSuccess;

/**
 * 小写字母
 */
class LowerLettersRule implements PasswdStrengthRule
{

    protected $length;

    protected $message;

    public function __construct($length = 1, $message = "密码必须包含至少一个小写字母")
    {
        $this->length = $length;
        $this->message = $message;
    }

    function handle($password)
    {
        if (!preg_match('/[a-z]/', $password)) {
            $passwdStrengthError = new PasswdStrengthError();
            $passwdStrengthError->setMessage($this->message);
            $passwdStrengthError->setName("lowerLetters");
            return $passwdStrengthError;
        }
        $passwdStrengthSuccess = new PasswdStrengthSuccess();
        $passwdStrengthSuccess->setName("lowerLetters");
        return $passwdStrengthSuccess;
    }

}